/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.media.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.media.entity.HkMediaCategoryCircle;
import com.thinkgem.jeesite.modules.hk.media.service.HkMediaCategoryCircleService;

/**
 * 自媒体圈子Controller
 * @author 罗天文
 * @version 2018-05-14
 */
@Controller
@RequestMapping(value = "${adminPath}/media/hkMediaCategoryCircle")
public class HkMediaCategoryCircleController extends BaseController {

	@Autowired
	private HkMediaCategoryCircleService hkMediaCategoryCircleService;
	
	@ModelAttribute
	public HkMediaCategoryCircle get(@RequestParam(required=false) String id) {
		HkMediaCategoryCircle entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkMediaCategoryCircleService.get(id);
		}
		if (entity == null){
			entity = new HkMediaCategoryCircle();
		}
		return entity;
	}
	
	@RequiresPermissions("media:hkMediaCategoryCircle:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkMediaCategoryCircle hkMediaCategoryCircle, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkMediaCategoryCircle> page = hkMediaCategoryCircleService.findPage(new Page<HkMediaCategoryCircle>(request, response), hkMediaCategoryCircle); 
		model.addAttribute("page", page);
		return "hk/media/hkMediaCategoryCircleList";
	}

	@RequiresPermissions("media:hkMediaCategoryCircle:view")
	@RequestMapping(value = "form")
	public String form(HkMediaCategoryCircle hkMediaCategoryCircle, Model model) {
		model.addAttribute("hkMediaCategoryCircle", hkMediaCategoryCircle);
		return "hk/media/hkMediaCategoryCircleForm";
	}

	@RequiresPermissions("media:hkMediaCategoryCircle:edit")
	@RequestMapping(value = "save")
	public String save(HkMediaCategoryCircle hkMediaCategoryCircle, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkMediaCategoryCircle)){
			return form(hkMediaCategoryCircle, model);
		}

		hkMediaCategoryCircleService.save(hkMediaCategoryCircle);
		addMessage(redirectAttributes, "保存自媒体圈子成功");
		return "redirect:"+Global.getAdminPath()+"/media/hkMediaCategoryCircle/?repage";
	}
	
	@RequiresPermissions("media:hkMediaCategoryCircle:edit")
	@RequestMapping(value = "delete")
	public String delete(HkMediaCategoryCircle hkMediaCategoryCircle, RedirectAttributes redirectAttributes) {
		hkMediaCategoryCircleService.delete(hkMediaCategoryCircle);
		addMessage(redirectAttributes, "删除自媒体圈子成功");
		return "redirect:"+Global.getAdminPath()+"/media/hkMediaCategoryCircle/?repage";
	}

}